<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
<xsl:stylesheet 
	version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:msxml="urn:schemas-microsoft-com:xslt"
	xmlns:pm.library="urn:pm.library"
	xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:CommerceLibrary="urn:CommerceLibrary" 
	exclude-result-prefixes="msxml pm.library umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets CommerceLibrary ">

  <xsl:output method="xml" omit-xml-declaration="yes"/>

  <xsl:param name="currentPage"/>

  <xsl:variable name="folder" select="/macro/folder" />

  <xsl:template match="/">
  
    <xsl:variable name="result" select="pm.library:GetPrivateMessages($folder)" />
    <xsl:choose>
      <xsl:when test="string-length($result/error) = 0">
	  
        <table>
          <tr>
            <th>From</th>
            <th>Subject</th>
          </tr>
          <xsl:for-each select="$result//privatemessage">
            <tr>
              <td>
                <xsl:call-template name="render-field">
		<xsl:with-param name="privatemessage" select="." />
		<xsl:with-param name="field" select="umbraco.library:GetMemberName(message/memberid)" />
                </xsl:call-template>
              </td>
              <td>
                <xsl:call-template name="render-field">
		<xsl:with-param name="privatemessage" select="." />
		<xsl:with-param name="field" select="message/subject" />
                </xsl:call-template>
              </td>
            </tr>
          </xsl:for-each>
        </table>
		
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$result/error" />
      </xsl:otherwise>
    </xsl:choose>

    <!--
    <textarea>
      <xsl:copy-of select="$result" />
    </textarea>
    -->
  </xsl:template>

  <xsl:template name="render-field">
    <xsl:param name="privatemessage" />
    <xsl:param name="field" />

    <xsl:choose>
      <xsl:when test="$privatemessage/recipient/status = 'Unread'">
        <strong>
          <a href="/private/pmview.aspx?id={$privatemessage/message/messageid}">
            <xsl:value-of select="$field" />
	 </a>
        </strong>
       </xsl:when>
       <xsl:otherwise>
         <a href="/private/pmview.aspx?id={$privatemessage/message/messageid}">
           <xsl:value-of select="$field" />
	</a>
       </xsl:otherwise>
     </xsl:choose>

  </xsl:template>
  
</xsl:stylesheet>
